/**
 * This file is part of 1genia trampoline
 * Copyright (C) 2007-2008 1genia (contact@1genia.com)
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; version 3 of the License. 
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details. 
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; see the file COPYING.TXT.  If not,
 * write to the Free Software Foundation, Inc., 51 Franklin Street,
 * Fifth Floor, Boston, MA 02110-1301, USA. 
 **/
package com.genia.toolbox.projects.toolbox_basics_project.business.dao.impl;

import com.genia.toolbox.basics.exception.technical.TechnicalException;
import com.genia.toolbox.persistence.criteria.Criteria;
import com.genia.toolbox.persistence.dao.impl.AbstractSpecificDAO;
import com.genia.toolbox.persistence.exception.PersistenceException;
import com.genia.toolbox.projects.toolbox_basics_project.bean.model.ByNameReferenceable;
import com.genia.toolbox.projects.toolbox_basics_project.bean.model.TemplateType;
import com.genia.toolbox.projects.toolbox_basics_project.business.dao.ByNameReferenceableDAO;

/**
 * implementation of ByNameReferenceableDAO.
 */
public class ByNameReferenceableDAOImpl
    extends AbstractSpecificDAO<ByNameReferenceable>
    implements ByNameReferenceableDAO
{

  /**
   * returns a new instance of the object handled by this DAO.
   * 
   * @return a new instance of the object handled by this DAO
   * @throws TechnicalException
   *           if an error occured
   * @see com.genia.toolbox.persistence.dao.impl.AbstractSpecificDAO#newObject()
   */
  @Override
  public ByNameReferenceable newObject()
      throws TechnicalException
  {
    throw new UnsupportedOperationException();
  }



  /**
   * constructor.
   */
  public ByNameReferenceableDAOImpl()
  {
    super(ByNameReferenceable.class);
  }



  /**
   * returns the {@link ByNameReferenceable} of type TYPE with the given
   * referenceName.
   * 
   * @param <TYPE>
   *          the type of the object to retrieve
   * @param objectClass
   *          the clas sof the type of the object to retrieve
   * @param referenceName
   *          the reference name
   * @return the {@link ByNameReferenceable} of type TYPE with the given
   *         referenceName
   * @throws PersistenceException
   *           when an error occured
   * @see com.genia.toolbox.projects.toolbox_basics_project.business.dao.ByNameReferenceableDAO#getObjectByReferenceName(java.lang.Class,
   *      java.lang.String)
   */
  public <TYPE extends ByNameReferenceable> TYPE getObjectByReferenceName(Class<TYPE> objectClass, String referenceName)
      throws PersistenceException
  {
    Criteria<TYPE> criteria = getCriteria(objectClass);
    criteria.addRestriction(equals(getPropertyField(TemplateType.NAME_REFERENCE_NAME), getConstantField(referenceName)));
    return simpleFindUnique(criteria);
  }

}
